<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
  </body>
  <script>
    const unique = (arr, key) => {
      if (!arr) return arr;
      if (key === undefined) return [...new Set(arr)];
      // 判断执行哪种方法回调
      const map = {
        string: (e) => e[key],
        function: (e) => key[e],
      };
      console.log(key);
      const fn = map[typeof key];
      console.log(fn);
      const obj = arr.reduce((o, e) => {
        console.log("fn(e)-->", fn(e));
        console.log("o[fn(e)]-->", o[fn(e)]);
        console.log("e-->", e);
        console.log("o-->", o);
        return (o[fn(e)] = e), o;
      }, {});
      return Object.values(obj);
    };
  </script>
</html>
